# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.action_chains import ActionChains
import unittest
import random
import time
from cookies import lasthopes, randomword
import re
import string
import sys
from selenium.webdriver.common.keys import Keys
from PIL import Image
from os import remove, listdir, sep
from os.path import basename, isfile
import tempfile
from warnings import warn
from basecart import BaseCart

class cart_empty_add(BaseCart):
    def test_cart_empty_add(self):
        driver = self.driver
        #Random category
        cat = random.choice(driver.find_elements_by_css_selector("a.b-header-nav-anchor"))
        cat.click()
        #Random item
        itm_url = self.get_item().replace("http://", "").replace("https://", "")
        #Buy and inspect cart button
        self.buy_item()
        #Check item exists in cart
        self.get_url("/showparam/magaz-cart.html")
        cart_itm_url = WebDriverWait(driver, timeout=10)\
                   .until(lambda dr: driver.find_element_by_css_selector("div._b-cart-order-item-main-product")\
                                           .find_element_by_tag_name("a")).get_attribute("href")
        assert itm_url in cart_itm_url, 'Item url in cart '+cart_itm_url+' not matched item url '+itm_url
